package com.dh.bm.dao.impl;

import com.dh.bm.common.JDBCUtil;
import com.dh.bm.dao.CategoryDao;
import com.dh.bm.entity.Category;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class CategoryDaoImpl implements CategoryDao {
    @Override
    public List<Category> selectAll() {
        return null;
    }

    @Override
    public Category selectById(int id) {
        String sql = "select * from category where cid = ?";
        PreparedStatement ps = JDBCUtil.getStatement(sql);
        ResultSet resultSet = null;
        try {
            ps.setInt(1, id);
            resultSet = ps.executeQuery();
            while (resultSet.next()) {
                int cid = resultSet.getInt(1);
                String name = resultSet.getString(2);
                Category category = new Category();
                category.setCid(cid);
                category.setName(name);
                return category;
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JDBCUtil.close(resultSet);
        }
        return null;
    }

    @Override
    public boolean updateById(int id, Category category) {
        return false;
    }

    @Override
    public boolean deleteById(int id) {
        return false;
    }

    @Override
    public boolean insert(Category category) {
        return false;
    }
}
